﻿
Imports System.Data
Imports VSModel
Imports Cls_Common
Imports SecurityService
Partial Class Control_ProDotuoi_Create
    Inherits System.Web.UI.UserControl
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Session("curSA") = Nothing
            Session("ListGenPO") = Nothing

            'Dim script As ScriptManager = ScriptManager.GetCurrent(Me.Page)
            'If Not script Is Nothing AndAlso script.IsInAsyncPostBack Then
            '    ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType, "duyjs", "ajaxJquery()", True)
            'Else
            '    Me.Page.ClientScript.RegisterStartupScript(Me.Page.GetType(), "duyjs", String.Concat("Sys.Application.add_load(function(){", "ajaxJquery()", "});"), True)
            'End If
            'txtOrderDate.Text = Now.Date.ToString("dd/MM/yyyy")
            'BindListStore()
            'ddlStore.Attributes.Add("onchange", "return GenerateOrderId()")
        End If

    End Sub
    'Protected Sub BindListStore()
    '    Dim userId As Integer = Session("UserId")
    '    Using Data As New VSEntities
    '        Dim p = (From q In Data.Stores Join k In Data.UserStores On q.StoreId Equals k.StoreId Where k.UserId = userId Select q Order By q.Title).ToList

    '        With ddlStore
    '            .DataValueField = "StoreId"
    '            .DataTextField = "Title"
    '            .DataSource = p
    '            .DataBind()
    '            .Items.Insert(0, New ListItem("--- Chọn ---", ""))

    '        End With
    '    End Using
    'End Sub

    Protected Sub btnSaveOrderDetail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSaveOrderDetail.Click

        If Session("Username") = Nothing Then
            Excute_Javascript("Alertbox('Bạn chưa đăng nhập vào hệ thống. vui lòng đăng nhập !');window.location ='../../Login.aspx';", Me.Page, True)
            Exit Sub
        End If
        Using data As New VSEntities
            Dim p As New VSModel.ProDoTuoi
            Dim tit = txtTitle.Text
            Dim q = (From x In data.ProDoTuois Where x.Title = tit Select x.Title).FirstOrDefault
            If q Is Nothing Then
                Try
                    p.Title = txtTitle.Text
                    p.Description = txtDescription.Text
                    data.ProDoTuois.AddObject(p)
                    data.SaveChanges()
                    'logInfo = "Insert OrderDetail of Order: " & txtDoc_serial_no.Text & "<br>" & logInfo
                    ' Insert_App_Log(logInfo, Function_Name.Order, Audit_Type.Create, Request.ServerVariables("REMOTE_ADDR"), Session("UserName"))
                    Excute_Javascript("Alertbox('Cập nhật dữ liệu thành công.'); ", Me.Page, True)
                    Response.Redirect("List.aspx?ID=" & p.Id.ToString)


                Catch ex As Exception

                    '    Excute_Javascript("Alertbox('Cập nhật chi tiết bán hàng thất bại.');", Me.Page, True)
                    '    Exit Sub
                    'End Try
                    '    End If
                    'Catch ex As Exception

                    '    Excute_Javascript("Alertbox('Cập nhật Order thất bại.');", Me.Page, True)
                End Try
                '    End If
                'End If
            Else
                Excute_Javascript("Alertbox('Độ tuổi  đã tồn tại trong hệ thống')", Me.Page, True)
            End If

        End Using
    End Sub

    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Response.Redirect("List.aspx")
    End Sub
End Class
